Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: introduce useSocial and useSocialProfile hooks #22

Open
wants to merge 1 commit into
base: beta
Choose a base branch
from

Conversation

shelegdmitriy
Copy link

Description

This PR includes the following hooks for convenience:

  • useSocial() for easily accessing the Social SDK instance shared by the provider.
  • useSocialProfile() for easily accessing any account ID's social profile.

Context

Some time ago, something similar to this sdk has been created here and recently that module was ported as a separate repo here.

near-social-js has almost the same functionality (maybe even more) as near-social-db-sdk. That's why I decided to contribute to your module (and maybe collaborate in a future) to avoid duplicate modules.

Also, feel free to check out near-social-db-sdk on your own and leave your thoughts on what would you like to port to this module too

Type of change

  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 🏗️ Build configuration (CI configuration, scaffolding etc.)
  • 🐛 Bug fix (non-breaking change which fixes an issue)
  • 📝 Documentation update(s)
  • 📦 Dependency update(s)
  • 👩🏽‍💻 Improve developer experience
  • ⚡ Improve performance
  • ✨ New feature (non-breaking change which adds functionality)
  • ♻ Refactor
  • ⏪ Revert changes
  • 🧪 New tests or updates to existing tests

@elliotBraem
Copy link
Contributor

Hey @shelegdmitriy, thanks for the pull request! I'm glad to hear we can join forces on this SDK, maybe we can start a chat or schedule a call sometime to fully understand all your requirements and how you plan to use it. Also -- we discuss this project in the Build DAO telegram chat, under "NearSocialJS" topic, feel free to join!

Regarding the pull request -- my first feeling is that we should keep any react-specific hooks and components separate from the core package -- we can make this a monorepo and split this into several packages, for this: @near-social-js/react

Although I also don't want to slow down any progress -- I would be fine with merging this now into the v1 release with the understanding that this will change, but I think this will introduce more headaches on both sides if it's not implemented 100% as we want it. With that said, we're about to release v1 this week, and I think I'd recommend keeping these hooks and provider in your own app and reference v1 methods, until we feel confident + stable to move these into this package.

What do you think @kieranroneill @jaswinder6991 ?

@jaswinder6991
Copy link
Collaborator

Hey @shelegdmitriy, thanks for the pull request! I'm glad to hear we can join forces on this SDK, maybe we can start a chat or schedule a call sometime to fully understand all your requirements and how you plan to use it. Also -- we discuss this project in the Build DAO telegram chat, under "NearSocialJS" topic, feel free to join!

Regarding the pull request -- my first feeling is that we should keep any react-specific hooks and components separate from the core package -- we can make this a monorepo and split this into several packages, for this: @near-social-js/react

Although I also don't want to slow down any progress -- I would be fine with merging this now into the v1 release with the understanding that this will change, but I think this will introduce more headaches on both sides if it's not implemented 100% as we want it. With that said, we're about to release v1 this week, and I think I'd recommend keeping these hooks and provider in your own app and reference v1 methods, until we feel confident + stable to move these into this package.

What do you think @kieranroneill @jaswinder6991 ?

Thanks @elliotBraem for sharing your thoughts.
I completely agree with you here. We do not want to introduce framework specific concepts like Hooks to the core package.
I think this implementation would be better off in its own package. I am not sure if we would want to manage it in this repo just yet even in a monorepo for now.

That being said, we are also figuring out a lot of things about the library at the moment. Probably in the future we would have a clearer picture if we need anything like this.
Hopefully after v1, we can publish something for our next steps.

@shelegdmitriy we look forward to talking to you and understand what are your requirements and needs for social-db-sdk, we can indeed reduce duplicated efforts.

Copy link
Collaborator

@kieranroneill kieranroneill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First off, nice work @shelegdmitriy!

As @elliotBraem suggested, I think splitting this into a monorepo would be a good idea. The "core" work that is already in here is agnostic any JS environment and adding in React would cause issues for those that want to use this outside of React.

We are imminently about to push v1 release, and I think the first priority will be setup a monorepo and use your contribution as the React repo. As @elliotBraem mentioned, I like the @builddao/near-social-js/react package.


const { social } = result.current;

let data: any;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this will fail the linter. For objects, we can use Record<string, unknown>.

useSocial: jest.fn(() => ({
social: {
async get({ keys }: { keys: string[] }) {
return keys.reduce((acc, key) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.reduce allows you to declare the the type to cast, rather than using the as notation.

keys.reduce<Record<string, unknown>>((acc, key) => {
  acc[key] = { profile: { name: 'TestUser' } };
  return acc;
}, {});

async getVersion() {
return '1.0.0';
},
async set({ data }: { data: Record<string, any> }) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As before, Record<string, unknown> is favoured over using any.

@shelegdmitriy
Copy link
Author

@kieranroneill @jaswinder6991 @elliotBraem thank you all for your feedback! I agree with everything that you described here.

I think splitting this into a monorepo would be a good idea. The "core" work that is already in here is agnostic any JS environment and adding in React would cause issues for those that want to use this outside of React.

I like this solution and happy to improve this PR according to your suggestions. What is the next steps for me with this PR? Should I just close this one and re-open it in a monorepo? Do you want me to improve it with your suggestions and leave it here instead without closing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants